//-----------------------------------------------------------------------
// <copyright file="a_DomDocumentDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_DomDocumentDAOBase
    {
        #region Common methods
        public virtual a_DomDocument Createa_DomDocumentFromReader(IDataReader reader)
        {
            a_DomDocument item = new a_DomDocument();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("DomDocID"))) item.DomDocID = (int)reader["DomDocID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Aboutus"))) item.Aboutus = (string)reader["Aboutus"];
                if (!reader.IsDBNull(reader.GetOrdinal("PrivacyPolicy"))) item.PrivacyPolicy = (string)reader["PrivacyPolicy"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserAgreement"))) item.UserAgreement = (string)reader["UserAgreement"];
                if (!reader.IsDBNull(reader.GetOrdinal("WelcomeMsg"))) item.WelcomeMsg = (string)reader["WelcomeMsg"];
                if (!reader.IsDBNull(reader.GetOrdinal("SaleOrder"))) item.SaleOrder = (string)reader["SaleOrder"];
                if (!reader.IsDBNull(reader.GetOrdinal("Saleorder_Noquote"))) item.Saleorder_Noquote = (string)reader["Saleorder_Noquote"];
                if (!reader.IsDBNull(reader.GetOrdinal("Cart"))) item.Cart = (string)reader["Cart"];
                if (!reader.IsDBNull(reader.GetOrdinal("ThankYouMsg"))) item.ThankYouMsg = (string)reader["ThankYouMsg"];
                if (!reader.IsDBNull(reader.GetOrdinal("Login"))) item.Login = (string)reader["Login"];
                if (!reader.IsDBNull(reader.GetOrdinal("Register"))) item.Register = (string)reader["Register"];
                if (!reader.IsDBNull(reader.GetOrdinal("Checkout3"))) item.Checkout3 = (string)reader["Checkout3"];
                if (!reader.IsDBNull(reader.GetOrdinal("Contact"))) item.Contact = (string)reader["Contact"];
                if (!reader.IsDBNull(reader.GetOrdinal("NoCookie"))) item.NoCookie = (string)reader["NoCookie"];
                if (!reader.IsDBNull(reader.GetOrdinal("NewCustomerTerms"))) item.NewCustomerTerms = (string)reader["NewCustomerTerms"];
                if (!reader.IsDBNull(reader.GetOrdinal("NewOrderTerms"))) item.NewOrderTerms = (string)reader["NewOrderTerms"];
                if (!reader.IsDBNull(reader.GetOrdinal("GiftCertNote"))) item.GiftCertNote = (string)reader["GiftCertNote"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom1"))) item.Custom1 = (string)reader["Custom1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom2"))) item.Custom2 = (string)reader["Custom2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom3"))) item.Custom3 = (string)reader["Custom3"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom4"))) item.Custom4 = (string)reader["Custom4"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom5"))) item.Custom5 = (string)reader["Custom5"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom6"))) item.Custom6 = (string)reader["Custom6"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom7"))) item.Custom7 = (string)reader["Custom7"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom8"))) item.Custom8 = (string)reader["Custom8"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom9"))) item.Custom9 = (string)reader["Custom9"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom10"))) item.Custom10 = (string)reader["Custom10"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom11"))) item.Custom11 = (string)reader["Custom11"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom12"))) item.Custom12 = (string)reader["Custom12"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom13"))) item.Custom13 = (string)reader["Custom13"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom14"))) item.Custom14 = (string)reader["Custom14"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom15"))) item.Custom15 = (string)reader["Custom15"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom16"))) item.Custom16 = (string)reader["Custom16"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom17"))) item.Custom17 = (string)reader["Custom17"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom18"))) item.Custom18 = (string)reader["Custom18"];
                if (!reader.IsDBNull(reader.GetOrdinal("MesDeclined"))) item.MesDeclined = (string)reader["MesDeclined"];
                if (!reader.IsDBNull(reader.GetOrdinal("Toplist"))) item.Toplist = (string)reader["Toplist"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_DomDocument methods
            
        public virtual void Createa_DomDocument(a_DomDocument a_DomDocument)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomDocuments_ins");
                
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_DomDocument.DomainID);
                database.AddInParameter(dbCommand, "@Aboutus", DbType.AnsiString, a_DomDocument.Aboutus);
                database.AddInParameter(dbCommand, "@PrivacyPolicy", DbType.AnsiString, a_DomDocument.PrivacyPolicy);
                database.AddInParameter(dbCommand, "@UserAgreement", DbType.AnsiString, a_DomDocument.UserAgreement);
                database.AddInParameter(dbCommand, "@WelcomeMsg", DbType.AnsiString, a_DomDocument.WelcomeMsg);
                database.AddInParameter(dbCommand, "@SaleOrder", DbType.AnsiString, a_DomDocument.SaleOrder);
                database.AddInParameter(dbCommand, "@Saleorder_Noquote", DbType.AnsiString, a_DomDocument.Saleorder_Noquote);
                database.AddInParameter(dbCommand, "@Cart", DbType.AnsiString, a_DomDocument.Cart);
                database.AddInParameter(dbCommand, "@ThankYouMsg", DbType.AnsiString, a_DomDocument.ThankYouMsg);
                database.AddInParameter(dbCommand, "@Login", DbType.AnsiString, a_DomDocument.Login);
                database.AddInParameter(dbCommand, "@Register", DbType.AnsiString, a_DomDocument.Register);
                database.AddInParameter(dbCommand, "@Checkout3", DbType.AnsiString, a_DomDocument.Checkout3);
                database.AddInParameter(dbCommand, "@Contact", DbType.AnsiString, a_DomDocument.Contact);
                database.AddInParameter(dbCommand, "@NoCookie", DbType.AnsiString, a_DomDocument.NoCookie);
                database.AddInParameter(dbCommand, "@NewCustomerTerms", DbType.AnsiString, a_DomDocument.NewCustomerTerms);
                database.AddInParameter(dbCommand, "@NewOrderTerms", DbType.AnsiString, a_DomDocument.NewOrderTerms);
                database.AddInParameter(dbCommand, "@GiftCertNote", DbType.AnsiString, a_DomDocument.GiftCertNote);
                database.AddInParameter(dbCommand, "@Custom1", DbType.AnsiString, a_DomDocument.Custom1);
                database.AddInParameter(dbCommand, "@Custom2", DbType.AnsiString, a_DomDocument.Custom2);
                database.AddInParameter(dbCommand, "@Custom3", DbType.AnsiString, a_DomDocument.Custom3);
                database.AddInParameter(dbCommand, "@Custom4", DbType.AnsiString, a_DomDocument.Custom4);
                database.AddInParameter(dbCommand, "@Custom5", DbType.AnsiString, a_DomDocument.Custom5);
                database.AddInParameter(dbCommand, "@Custom6", DbType.AnsiString, a_DomDocument.Custom6);
                database.AddInParameter(dbCommand, "@Custom7", DbType.AnsiString, a_DomDocument.Custom7);
                database.AddInParameter(dbCommand, "@Custom8", DbType.AnsiString, a_DomDocument.Custom8);
                database.AddInParameter(dbCommand, "@Custom9", DbType.AnsiString, a_DomDocument.Custom9);
                database.AddInParameter(dbCommand, "@Custom10", DbType.AnsiString, a_DomDocument.Custom10);
                database.AddInParameter(dbCommand, "@Custom11", DbType.AnsiString, a_DomDocument.Custom11);
                database.AddInParameter(dbCommand, "@Custom12", DbType.AnsiString, a_DomDocument.Custom12);
                database.AddInParameter(dbCommand, "@Custom13", DbType.AnsiString, a_DomDocument.Custom13);
                database.AddInParameter(dbCommand, "@Custom14", DbType.AnsiString, a_DomDocument.Custom14);
                database.AddInParameter(dbCommand, "@Custom15", DbType.AnsiString, a_DomDocument.Custom15);
                database.AddInParameter(dbCommand, "@Custom16", DbType.AnsiString, a_DomDocument.Custom16);
                database.AddInParameter(dbCommand, "@Custom17", DbType.AnsiString, a_DomDocument.Custom17);
                database.AddInParameter(dbCommand, "@Custom18", DbType.AnsiString, a_DomDocument.Custom18);
                database.AddInParameter(dbCommand, "@MesDeclined", DbType.AnsiString, a_DomDocument.MesDeclined);
                database.AddInParameter(dbCommand, "@Toplist", DbType.AnsiString, a_DomDocument.Toplist);
                database.AddOutParameter(dbCommand, "@DomDocID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_DomDocument.DomDocID = (int)database.GetParameterValue(dbCommand, "@DomDocID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_DomDocument methods
        
        public virtual void Updatea_DomDocument(a_DomDocument a_DomDocument)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomDocuments_upd");            
                
                database.AddInParameter(dbCommand, "@DomDocID", DbType.Int32, a_DomDocument.DomDocID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_DomDocument.DomainID);
                database.AddInParameter(dbCommand, "@Aboutus", DbType.AnsiString, a_DomDocument.Aboutus);
                database.AddInParameter(dbCommand, "@PrivacyPolicy", DbType.AnsiString, a_DomDocument.PrivacyPolicy);
                database.AddInParameter(dbCommand, "@UserAgreement", DbType.AnsiString, a_DomDocument.UserAgreement);
                database.AddInParameter(dbCommand, "@WelcomeMsg", DbType.AnsiString, a_DomDocument.WelcomeMsg);
                database.AddInParameter(dbCommand, "@SaleOrder", DbType.AnsiString, a_DomDocument.SaleOrder);
                database.AddInParameter(dbCommand, "@Saleorder_Noquote", DbType.AnsiString, a_DomDocument.Saleorder_Noquote);
                database.AddInParameter(dbCommand, "@Cart", DbType.AnsiString, a_DomDocument.Cart);
                database.AddInParameter(dbCommand, "@ThankYouMsg", DbType.AnsiString, a_DomDocument.ThankYouMsg);
                database.AddInParameter(dbCommand, "@Login", DbType.AnsiString, a_DomDocument.Login);
                database.AddInParameter(dbCommand, "@Register", DbType.AnsiString, a_DomDocument.Register);
                database.AddInParameter(dbCommand, "@Checkout3", DbType.AnsiString, a_DomDocument.Checkout3);
                database.AddInParameter(dbCommand, "@Contact", DbType.AnsiString, a_DomDocument.Contact);
                database.AddInParameter(dbCommand, "@NoCookie", DbType.AnsiString, a_DomDocument.NoCookie);
                database.AddInParameter(dbCommand, "@NewCustomerTerms", DbType.AnsiString, a_DomDocument.NewCustomerTerms);
                database.AddInParameter(dbCommand, "@NewOrderTerms", DbType.AnsiString, a_DomDocument.NewOrderTerms);
                database.AddInParameter(dbCommand, "@GiftCertNote", DbType.AnsiString, a_DomDocument.GiftCertNote);
                database.AddInParameter(dbCommand, "@Custom1", DbType.AnsiString, a_DomDocument.Custom1);
                database.AddInParameter(dbCommand, "@Custom2", DbType.AnsiString, a_DomDocument.Custom2);
                database.AddInParameter(dbCommand, "@Custom3", DbType.AnsiString, a_DomDocument.Custom3);
                database.AddInParameter(dbCommand, "@Custom4", DbType.AnsiString, a_DomDocument.Custom4);
                database.AddInParameter(dbCommand, "@Custom5", DbType.AnsiString, a_DomDocument.Custom5);
                database.AddInParameter(dbCommand, "@Custom6", DbType.AnsiString, a_DomDocument.Custom6);
                database.AddInParameter(dbCommand, "@Custom7", DbType.AnsiString, a_DomDocument.Custom7);
                database.AddInParameter(dbCommand, "@Custom8", DbType.AnsiString, a_DomDocument.Custom8);
                database.AddInParameter(dbCommand, "@Custom9", DbType.AnsiString, a_DomDocument.Custom9);
                database.AddInParameter(dbCommand, "@Custom10", DbType.AnsiString, a_DomDocument.Custom10);
                database.AddInParameter(dbCommand, "@Custom11", DbType.AnsiString, a_DomDocument.Custom11);
                database.AddInParameter(dbCommand, "@Custom12", DbType.AnsiString, a_DomDocument.Custom12);
                database.AddInParameter(dbCommand, "@Custom13", DbType.AnsiString, a_DomDocument.Custom13);
                database.AddInParameter(dbCommand, "@Custom14", DbType.AnsiString, a_DomDocument.Custom14);
                database.AddInParameter(dbCommand, "@Custom15", DbType.AnsiString, a_DomDocument.Custom15);
                database.AddInParameter(dbCommand, "@Custom16", DbType.AnsiString, a_DomDocument.Custom16);
                database.AddInParameter(dbCommand, "@Custom17", DbType.AnsiString, a_DomDocument.Custom17);
                database.AddInParameter(dbCommand, "@Custom18", DbType.AnsiString, a_DomDocument.Custom18);
                database.AddInParameter(dbCommand, "@MesDeclined", DbType.AnsiString, a_DomDocument.MesDeclined);
                database.AddInParameter(dbCommand, "@Toplist", DbType.AnsiString, a_DomDocument.Toplist);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_DomDocument methods
        public virtual void Deletea_DomDocument(int domDocID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomDocuments_del");
                
                database.AddInParameter(dbCommand, "@DomDocID", DbType.Int32, domDocID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_DomDocument methods
        
        public virtual a_DomDocument Geta_DomDocument(int domDocID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomDocuments_sel");
                
                database.AddInParameter(dbCommand, "@DomDocID", DbType.Int32, domDocID);
                
                a_DomDocument a_DomDocument =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_DomDocument = Createa_DomDocumentFromReader(reader);
                        reader.Close();
                    }
                }
                return a_DomDocument;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_DomDocumentList methods
        public virtual a_DomDocumentCollection Geta_DomDocumentList(a_DomDocumentColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomDocuments_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_DomDocumentCollection a_DomDocumentCollection = new a_DomDocumentCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_DomDocument a_DomDocument = Createa_DomDocumentFromReader(reader);
                        a_DomDocumentCollection.Add(a_DomDocument);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_DomDocumentCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_DomDocumentCollection Geta_DomDocumentList(a_DomDocumentColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_DomDocumentList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}